package com.xuxin.baby.adapter;

import android.widget.ImageView;

import com.blankj.utilcode.util.LogUtils;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.xuxin.baby.R;
import com.xuxin.baby.bean.ReaderVideoBean;
import com.xuxin.baby.glide.GlideApp;
import com.xuxin.baby.network.Retrofit;

import org.jetbrains.annotations.NotNull;

/**
 * Created by xu_xin
 * Created on 2020.08.28 0028
 * 首页推荐
 */
public class MainAdviseAdapter extends BaseMultiItemQuickAdapter<ReaderVideoBean.ResultBean.ItemsBean, BaseViewHolder> {
    RequestOptions options = new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10));

    public MainAdviseAdapter() {
        addItemType(0, R.layout.item_main_video);
        addItemType(1, R.layout.item_main_reader);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, ReaderVideoBean.ResultBean.ItemsBean itemsBean) {
        switch (holder.getItemViewType()) {
            case 0:
                holder.setText(R.id.item_main_video_name, itemsBean.getTitle());
                holder.setText(R.id.item_main_video_content, itemsBean.getSummary());
                /**
                 * 加载图片
                 */
                ImageView item_main_video_image = holder.getView(R.id.item_main_video_image);
                String mainVideoImage = Retrofit.image_url + itemsBean.getImageUrl();
                LogUtils.e("首页推荐_image = " + mainVideoImage);
                GlideApp.with(getContext()).load(mainVideoImage).placeholder(R.mipmap.img_placeholder280).apply(options).into(item_main_video_image);
                /**
                 * 是否付费
                 */
                ImageView item_main_video_free = holder.getView(R.id.item_main_video_free);
                if (itemsBean.isFree()) {
                    GlideApp.with(getContext()).load(R.mipmap.img_free).apply(options).into(item_main_video_free);
                } else {
                    GlideApp.with(getContext()).load(R.mipmap.img_free_false).apply(options).into(item_main_video_free);
                }
                break;
            case 1:
                holder.setText(R.id.item_main_reader_name, itemsBean.getTitle());
                holder.setText(R.id.item_main_reader_content, itemsBean.getSummary());
                ImageView item_main_reader_image = holder.getView(R.id.item_main_reader_image);
                String mainReaderImage = Retrofit.image_url + itemsBean.getImageUrl();
                LogUtils.e("首页推荐_image = " + mainReaderImage);
                GlideApp.with(getContext()).load(mainReaderImage).placeholder(R.mipmap.img_placeholder280).apply(options).into(item_main_reader_image);
                break;
        }
    }
}